package org.benjamin.tenancy.controller;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.benjamin.tenancy.domain.entity.Building;
import org.benjamin.tenancy.service.BuildingService;
import org.benjamin.tenancy.service.impl.UserUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "building")
public class BuildingController {
	
	private Logger logger = LogManager.getLogger();
	
	@Autowired(required = false)
	private BuildingService buildingService;
	
	@RequestMapping(value = "index")
	public String index(ModelMap modelMap) {
		String username = UserUnit.getUsername();
		List<Building> buildings = this.buildingService.findBuildingByUser(username, false);
		logger.info("查询到数据有{}",buildings.size());
		modelMap.addAttribute("buildings",buildings);
		return "building/index";
	}
	
	@GetMapping(value = "add_Building")
	public String addBuilding() {
		return "building/add";
	}

}
